package com.my.forum.controller;

import com.my.forum.common.AppResult;
import com.my.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类相关接口")
@RequestMapping("/Test")
@RestController
public class TestCtroller {
    @ApiOperation("测试接口1，你好")
    @GetMapping("/hello")
    public String hello(){
        return "hello,springboot";
    }


    @ApiOperation("测试接口2，显示抛出异常")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation("测试接口3，显示自定义异常抛出")
    @GetMapping("/appexception")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationException...");
    }

    @ApiOperation("测试接口4，传入姓名")
    @PostMapping("/helloByName")
    public String helloByName(@ApiParam(value = "姓名") @RequestParam("name") String name){
        return "hello:"+ name;
    }
}
